<template>
  <div class="nav-menu">
    <div class="logo">
      <span v-if="!colaPase" class="title">konwledgeCenter</span>
    </div>
    <el-menu
      default-active="1.1"
      class="el-menu-vertical"
      background-color="#0c2135"
      text-color="#b7bdc3"
      active-text-color="#0a60bd"
      unique-opened
      :collapse="colaPase"
    >
      <template v-for="item in userMenu" :key="item.id">
        <el-sub-menu :index="item.id + ''">
          <template #title>
            <span>{{ item.name }}</span>
          </template>
          <template v-for="subitem in item.children" :key="subitem.id">
            <el-menu-item :index="subitem.id + ''" @click="changePage(subitem.url)">
              <span>{{ subitem.name }}</span>
            </el-menu-item>
          </template>
        </el-sub-menu>
      </template>
    </el-menu>
  </div>
</template>

<script setup lang="ts" >
import { ref } from 'vue'
import { useRouter } from 'vue-router'
    const router = useRouter()
    const colaPase = ref(false)
    const userMenu = ref([
      { 
        id: '1',
        name: '地图相关',
        children: [
          { id: '1.1', name: 'Echarts地图', url: '/echarts' },
          { id: '1.2', name: '百度地图', url: '/baidu' },
          { id: '1.3', name: '高德地图', url: '/gaode' },
        ]
      }
    ])

    const changePage = (path: string) => router.push(path)
</script>

<style scoped lang="less">
.nav-menu {
  height: 100%;
  .logo {
    display: flex;
    height: 28px;
    padding: 12px 10px 8px 10px;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    .img {
      height: 100%;
      margin: 0 10px;
    }
    .title {
      font-size: 16px;
      font-weight: 700;
      color: #333333;
    }
  }
  .el-menu {
    border-right: none;
  }
  .el-menu-item {
    color: #333333;
    padding-left: 50px !important;
    background-color: #fff !important;
  }

  :deep(.el-sub-menu__title) {
    color: #333333;
    background-color: #fff !important;
  }

  .el-menu-item:hover {
    color: #1327B2 !important; // 菜单
  }
  :deep(.el-sub-menu) {
    color: #333333 !important; // 菜单
    background-color: #fff !important;
  }

  .el-menu-item.is-active {
    color: #fff !important;
    background-color: #0a60bd !important;
  }
}
</style>
